//
//  XLEmptyFootView.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/3.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLEmptyFootView.h"
#import "XLPersonCenterTool.h"

@interface XLEmptyFootView ()

//提示图
@property (nonatomic, strong) UIImageView *  titleImageView;

//提示语
@property (nonatomic, strong) UILabel *  titleLbl;

//按钮（如果需要显示按钮，例如 断网重连）
@property (nonatomic, strong) UIButton *  reConnectBt;

@property (nonatomic, strong) AFNetworkReachabilityManager *manager;

@end

@implementation XLEmptyFootView

- (instancetype)init
{
    self = [super init];
    
    if (self) {
        
        /**
         绘制界面
         */
        [self setCustomeView];
    }
    
    return self;
}

#pragma mark    -   -   - 绘制界面显示 -  -   -

- (void)setCustomeView
{
    self.titleImageView = [[UIImageView alloc] init];
    
    self.titleImageView.image = [[UIImage imageNamed:@"pic_nothing_n"] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    [self addSubview:self.titleImageView];
    
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(135);
        make.centerX.equalTo(self.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(120, 120));
    }];
    
    //提示语
    self.titleLbl = [[UILabel alloc] init];
    self.titleLbl.font = [UIFont fontWithName:kFontNamePFRegular size:14];
    self.titleLbl.textColor = RGB(102, 102, 102);
    self.titleLbl.textAlignment = NSTextAlignmentCenter;
    self.titleLbl.text = @"还木有内容呢～";
    [self addSubview:self.titleLbl];
    
    [self.titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleImageView.mas_bottom).offset(16);
        make.centerX.equalTo(self.mas_centerX);
    }];
    
    //重连网络
    self.reConnectBt = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.reConnectBt.frame = CGRectMake(0, 0, kScale(144), 36);
    
    self.reConnectBt.layer.cornerRadius = 3;
    self.reConnectBt.layer.masksToBounds = YES;
    
    self.reConnectBt.hidden = YES;
    
    [self.reConnectBt setTitle:@"重连" forState:(UIControlStateNormal)];
    [self.reConnectBt setTitleColor:RGB(255, 187, 1) forState:(UIControlStateNormal)];
    
    [self.reConnectBt addTarget:self action:@selector(reFreshConnect:) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.reConnectBt.layer.borderWidth = 1.0f;
    self.reConnectBt.layer.borderColor = [UIColor colorWithRed:255/255.0 green:187/255.0 blue:1/255.0 alpha:1].CGColor;
    [self addSubview:self.reConnectBt];
    
    [self.reConnectBt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLbl).offset(56);
        make.centerX.equalTo(self.titleLbl.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(144, 36));
    }];
    
    //判断网络是否给力
    //打开网络检测
    self.manager = [AFNetworkReachabilityManager sharedManager];
    [self.manager startMonitoring];
    
    [self checkReachability];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
}

#pragma mark    - - - 点击重新刷新 - - -

- (void)reFreshConnect:(UIButton *)sender
{
    NSLog(@"刷新网络请求");
    
    if (self.reConnectBt.hidden == NO) {
        
        if (self.refreshReach) {
            
            self.refreshReach();
            
        }
        
    }
}

#pragma mark - - - 网络检测 - - -

- (void)checkReachability
{
    
    
    
    @weakify(self)
    [self.manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        @strongify(self)
        switch (status) {
            
            case AFNetworkReachabilityStatusNotReachable:{
                
                //无网络状态
                self.titleLbl.text = @"网络不太给力呢～";
                self.reConnectBt.hidden = NO;
                
                break;
            }
                
                
            default:
                
                self.titleLbl.text = @"还木有内容呢～";
                self.reConnectBt.hidden = YES;
                
                break;
        }
        
    }];
}

@end
